package com.ruoyi.iot.service.impl;

import com.ruoyi.iot.domain.entity.DeviceThresholdConfig;
import com.ruoyi.iot.mapper.DeviceThresholdConfigMapper;
import com.ruoyi.iot.service.DeviceThresholdConfigService;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 阈值配置服务实现
 */
@Service
public class DeviceThresholdConfigServiceImpl implements DeviceThresholdConfigService {

    private final DeviceThresholdConfigMapper thresholdConfigMapper;

    public DeviceThresholdConfigServiceImpl(DeviceThresholdConfigMapper thresholdConfigMapper) {
        this.thresholdConfigMapper = thresholdConfigMapper;
    }

    @Override
    public List<DeviceThresholdConfig> listAll() {
        return thresholdConfigMapper.selectAll();
    }

    @Override
    public List<java.util.Map<String, Object>> pageWithMetricLabel(DeviceThresholdConfig query) {
        return thresholdConfigMapper.selectWithMetricLabel(query);
    }

    @Override
    public List<DeviceThresholdConfig> listByDevice(String deviceId) {
        return thresholdConfigMapper.selectByDeviceId(deviceId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int create(DeviceThresholdConfig config) {
        return thresholdConfigMapper.insert(config);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int update(DeviceThresholdConfig config) {
        return thresholdConfigMapper.update(config);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delete(Long id) {
        return thresholdConfigMapper.deleteById(id);
    }
}
